﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProjectCore.Application;
using ProjectCore.Domain.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ProjectCore.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RolesController : ControllerBase
    {
        private readonly IAppRoles appRoles;
        public RolesController(IAppRoles _appRoles)
        {
            appRoles = _appRoles;
        }
        /// <summary>
        /// 获取角色表集合
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetRoless()
        {
            List<Roles> roles =await appRoles.GetRoles();
            return Ok(new { data = roles });
        }
        /// <summary>
        /// 添加角色
        /// </summary>
        /// 
        /// <param name="roles"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> Add(Roles roles)
        {
            int n =await appRoles.Add(roles);
            return Ok(new { data = n });
        }
        /// <summary>
        /// 反填角色数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task< ActionResult> Edit(int Id)
        {
            Roles roles =await appRoles.Edit(Id);
            return Ok(new { data = roles });
        }
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> IsDeleted(int Id)
        {
            int n = await appRoles.IsDel(Id);
            return Ok(new { data = n });
        }
        /// <summary>
        /// 修改角色表
        /// </summary>
        /// <param name="roles"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ActionResult> Upt(Roles roles)
        {
            int n =await appRoles.Upt(roles);
            return Ok(new { data = n });
        }
    }
}
